<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\api\model\Wx;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }


    /**
     * @MethodName 获取分享小程序二维码
     * @Author     Allen
     * @DateTime   2021-11-15T15:15:20+0800
     * @return     [type]
     */
    public function getUnlimited($value='')
    {
        // 自定义小程序参数，例如id
        $scene = $this->request->post("scene", '');
        if ( !$scene ) {
            $this->error('請傳遞參數',[]);
        }
        // 页面 page
        $page = $this->request->post("page", '');
        // 要打开的小程序版本。正式版为 "release"，体验版为 "trial"，开发版为 "develop"
        $env_version = $this->request->post("env_version", 'trial');
        $Wx = new Wx();
        $package = $Wx->getUnlimit($scene,$page,$env_version);
        if ( $package['code'] != 200 ) {
            $this->error('請求失敗');
        }
        $url = '/uploads/code/'.md5($scene).'_appcode.png';

        $path['pic'] = $url;
        $this->success('請求成功',$path);

    }

    public function diy()
    {
        $row = Db::name('config')->where(['name'=>'xcx_page_index'])->field('id,value')->find();
        if($row['id']){
            $page = json_decode($row['value'],true);
        }

        $this->success('請求成功', $page);
       
    }
}
